<?php
class ServiceLogger {

    protected static $instance = null;
    public static $log = true;

    function __construct() {
        /*$types = Doctrine::getTable('ActivityType')->findAll(Doctrine::HYDRATE_ARRAY);
        $this->arAll = array();
        $this->arAll['success'] = array();
        $this->arAll['failure'] = array();
        foreach($types as $type) {
            if($type['logSuccess']) {
                $this->arAll['success'][$type['class'].'.'.$type['action']]['id'] = $type['id'];
                $this->arAll['success'][$type['class'].'.'.$type['action']]['message'] = $type['successMessage'];
            }
            if($type['logFailure']) {
                $this->arAll['failure'][$type['class'].'.'.$type['action']]['id'] = $type['id'];
                $this->arAll['failure'][$type['class'].'.'.$type['action']]['message'] = $type['failureMessage'];
            }
        }*/
    }

    /**
     * Return the service logger singleton instance
     *
     * @return ServiceLogger
     */
    public static function getInstance() {
        if(!self::$instance) {
            self::$instance = new ServiceLogger();
        }
        return self::$instance;
    }

    /**
     * Log success service call
     *
     * @param string $service
     * @param string $method
     * @param string $duration
     */

    function logSuccess($service,$method,$duration) {
        /*if($this->hasToLogSuccess($service, $method)) {
            $userId = sfContext::getInstance()->getUser()->getAttribute('id');
            $activity = new Activity;
            $activity->user_id = $userId;
            $activity->activity_type_id = $this->arAll['success'][$service.'.'.$method]['id'];
            $activity->session = sfContext::getInstance()->getUser()->getAttribute('session');
            $activity->message = $this->arAll['success'][$service.'.'.$method]['message'];
            $activity->is_error = false;
            $activity->duration = $duration;
            $ar = debug_backtrace();
            $caller = $ar[2]['class'].'::'.$ar[2]['function'];
            $activity->caller = $caller;
            $activity->save();
        }*/
    }


    /**
     * Log failure
     *
     * @param string $service
     * @param string $method
     * @return bool
     */
    function logFailure($service,$method,$exception) {
        /*if($this->hasToLogFailure($service, $method)) {
            $userId = sfContext::getInstance()->getUser()->getAttribute('id');
            $activity = new Activity;
            $activity->user_id = $userId;
            $activity->activity_type_id = $this->arAll['failure'][$service.'.'.$method]['id'];
            $activity->session = sfContext::getInstance()->getUser()->getAttribute('session');
            $activity->message = $this->arAll['success'][$service.'.'.$method]['message'];
            $activity->is_error = true;
            $activity->error_type = get_class($exception);
            $activity->error_message = $exception->getMessage();
            $activity->save();
        }*/

    }

    /**
     * If has log success
     *
     * @param string $service
     * @param string $method
     * @return bool
     */

    function hasToLogSuccess($service, $method){
        /*return self::$log && array_key_exists($service.'.'.$method,$this->arAll['success']);*/
    }
    /**
     * If has log failure
     *
     * @param string $service
     * @param string $method
     * @return bool
     */

    function hasToLogFailure($service, $method){
        /*return self::$log && array_key_exists($service.'.'.$method,$this->arAll['failure']);*/
    }
}
?>